package com.cenxi.ipdemo1.task;

import com.cenxi.ipdemo1.config.RedisDistributedLock;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
@AllArgsConstructor
public class BusiTask {

    private final RedisDistributedLock redisDistributedLock;

    @Scheduled(cron = "0/1 * * * * ?")
    public void task1() {
        if (redisDistributedLock.lock("task1", "task1")) {
            log.info("获取锁成功: {}", LocalDateTime.now().withNano(0));
            redisDistributedLock.unlock("task1", "task1");
        } else {
            log.info("获取锁失败: {}", LocalDateTime.now().withNano(0));
        }
    }
}
